<?php
//设置错误等级
error_reporting(0);
require 'Adapter.php';
//定义mysql数据库操作类
class Db_Adapter_Mysqli implements Db_Adapter{
    private $_dbLink;//数据库连接字符串标示

    /**
     * 数据库连接函数
     * @param $config数据库配置
     * @throw Db_Exception
     * @return resource
     * 
    */
    public function connect($config)
    {
        if($this->_dbLink = @mysqli_connect($config['host'],$config['user'],$config['password'],$config['database'])){
            if($config['charset']){
                @mysqli_set_charset($this->_dbLink,$config['charset']);
            }
        }
        return $this->_dbLink;
    }


    /**
     * @param string $query 数据库查询sql字符串
     * @param mixed $handle连接对象
     * @return resource
    */
    public function query($query, $handle)
    {
        if($reource = mysqli_query($handle,$query)){
            return $reource;
        }
    }
}


// $mysql = new Db_Adapter_Mysqli();
// $config = [
//     'host' => 'localhost',
//     'user' => 'root',
//     'password' => 'root',
//     'database' => 'bd_fresh',
//     'charset' => 'utf8'
// ];
// $link = $mysql->connect($config);
// $sql = "SELECT * FROM bd_supplier WHERE id > 10";
// $result = $mysql->query($sql,$link);
// while($row = mysqli_fetch_array($result)){
//     echo $row['company_name']."<br>";
// }
